package com.ed.context;

/**
 * 基于 ThreadLocal 封装工具类，用户保存和获取当前登录用户id
 */
public final class UserContext {
	
	private static ThreadLocal<Integer> threadLocal = new ThreadLocal<>();
	
	/**
	 * 设置值
	 *
	 * @param id
	 */
	public static void setCurrentUser(int id) {
		threadLocal.set(id);
	}
	
	/**
	 * 获取值
	 *
	 * @return
	 */
	public static int getCurrentUser() {
		return threadLocal.get();
	}
	
	/**
	 * 移除值
	 *
	 * @return
	 */
	public static void removeCurrentUser() {
		threadLocal.remove();
	}
}